Miniscript Templates (MinT)

About

Miniscript is a language for composing Bitcoin Script in a structured way, facilitating analysis, composition, and generic signing. It's a simplified, composable subset of the Bitcoin Script language. Developed to overcome limitations in writing complex spending conditions directly in Bitcoin Script, it enables formal verification and offers a more human-friendly interface.

Objective

  1. Each MinT provides an example of a common miniscript implementation.
  2. Each MinT is provided as is. While care is taken to ensure a high degree of quality. Developers and enthusiasts assume full responsibility for their usage1.
  3. Have reviewed templates that leverage Miniscript to assure there are not unintended ways of executing a valid spend beyond the intended Miniscript policy.

  4. Have standardized usages of Miniscript to streamline software and hardware wallet integrations.

  5. Have uniform on-chain usage of Miniscript templates for better privacy.


Submission Format

Name of Template

MinT-###-<description>

Policy Description

A 3-of-3 multisig quorum that transitions to a 2-of-3 after 90 days2

Policy Implementation

Input3:

thresh(3, pk(key1), pk(key2), pk(key_3), older(12960))

Output4:

thresh(3, pk(key1), s:pk(key2), s:pk(key_3), sln:older(12960))

A fragment note5.

s:X SWAP [X]
n:X [X] 0NOTEQUAL
l:X = or_i(0,X) IF 0 ELSE [X] ENDIF

A footnote6.

Resulting Bitcoin Script structure7.

<key_1> OP_CHECKSIG OP_SWAP <key_2> OP_CHECKSIG OP_ADD OP_SWAP <key_3>
OP_CHECKSIG OP_ADD OP_SWAP OP_IF
  0
OP_ELSE
  <a032> OP_CHECKSEQUENCEVERIFY OP_0NOTEQUAL
OP_ENDIF
OP_ADD 3 OP_EQUAL

Spending cost analysis8:

Script: 122 WU
Input: 166.250000 WU
Total: 288.250000 WU

Reference Tx

Provide a reference transaction so behavior and outcomes can be verified.

TxID:

testnet:13a204ec065f76878ee1f59f79b3eb2cea2b3fda4d8938e6cfa6a8394d090769

Additional Links

usage example

Additional Resources

github.com/sipa/miniscript/tree/master

bitcoin.sipa.be/miniscript


  1. Use at your own risk. 

  2. 144 blocks per day x 90 days = 12960 blocks additonal info here: miniscript.h 

  3. nSequence ≥ n > 0 (add link) older(NUM) ~> <NUM> CHECKSEQUENCEVERIFY additonal info here: miniscript.h 

  4. nLockTime ≥ n > 0 (add link) after(NUM) ~> <NUM> CHECKLOCKTIMEVERIFY additonal info here: miniscript.h 

  5. Given a script, be able to predict the cost of spending an output. 

  6. "f" Forced: dissatisfying this expression always requires a signature (predicting whether all dissatisfactions will be HASSIG). 

  7. "e" Expressive: this requires a unique unconditional dissatisfaction to exist, and forces all conditional dissatisfactions (if any) to require a signature. 

  8. "s" Signed: satisfying this expression always requires a signature (predicting whether all satisfactions will be HASSIG).